<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/


namespace Member\Model;
use Think\Model;
use \Org\Util\String;
    
class ShopSlideModel extends Model {

	function UploadSlide(){
		
		$filearray=M('File')->token(false)->where(" uid=$this->uid AND isuse=0 AND thumbcut is not null ")->limit(3)->select();
			
		if(!empty($filearray)){
			$data['uid']=$this->uid;
			$data['dateline']=NowTime();
			foreach($filearray as $file){
				$fid=$file['fid'];
				$data['thumbcut']=$file['thumbcut'];
				$data['filepath']=$file['filepath'];
				$data['fid']=$fid;
				if ($this->token(false)->create($data)){
					if($id=$this->token(false)->add()){
						M('File')->token(false)->where(" fid=$fid ")->save(array('isuse'=>1,'slide'=>$id));
					}
				}
			}
			
			$slidecount=intval($this->where(" uid=$this->uid ")->count())-3;
			if($slidecount>0){
				$model=new \Upload\Model\FileModel();
				$slidearray=$this->token(false)->where(" uid=$this->uid ")->limit($slidecount)->order('id ASC')->select();
				if($slidearray){
					foreach($slidearray as $slide){
						$model->DeleteUpload($slide['fid']);
						$id=$slide['id'];
						$this->token(false)->where(" id=$id ")->delete();
					}
				}
			}
			
			return true;
		}
		
		$this->error='没有图片上传!';
	   	return false;
	}
		
}

?>